package com.mlnx.netty.maibb.uitl;


import java.text.SimpleDateFormat;
import java.util.Date;

import static java.lang.Long.parseLong;

/**
 * 常用字符串操作
 */
public  class EasyStr {

	/**
	 * 短日期格式,2008-01-01
	 */
	public final static int SHORT_DATE = 2;

	private static String[] types = { "yyyy-MM-dd HH:mm:ss", // ENGLISH_DATE
			"yyyy年MM月dd日HH时mm分ss秒", // CHINESE_DATE
			"yyyy-MM-dd", // SHORT_DATE
			"HH:mm:ss" // ONLY_TIME
	};
	public static long differenceLong(String startLong, String endLong) {
		long result = 0;
		long start = parseLong(startLong);

		long end = parseLong(endLong);
		if (start >= end) {
			result = start - end;
		} else {
			result = end - start;
		}

		return result;
	}
	public static Date nowDate() {
		return new Date();
	}
	public static String today() {
		return now(SHORT_DATE);
	}

	/**
	 * 获取当前系统日期,格式为yyyy-MM-dd hh:mm:ss或yyyy年MM月dd日hh时mm分ss秒
	 *
	 * @param 类型
	 *            ,0-2008-08-08 08:08:08; 1-2008年08月08日08时08分08秒;
	 * @return 当前系统日期
	 */
	public static String now(int i) {
		return new SimpleDateFormat(types[i]).format(new Date());
	}
}
